<?php
class ml_biz_indexData
{
    
    /**
     *
     * 输入content数组，输出组装好的pinboard HTML数组
     * @param unknown_type $content数组
     *
     */
    private $aRid = array();
    private $aUid = array();
    private $aNicks = array();
    private $aAttitude = array();
    private $aLikeCnt = array();
    private $aCmtCnt = array();
    private $aQuoteCnt = array();//pin宝贝被转采数
    private $redis;//redis对象实例（防止多次实例化）
    private $uid;
    private $uniqueData=array();//统一后的数组
    private $is_share;
    private $ifme;
    private $content;
    private $feed;
    /**
     *
     * 输入content数组，输出组装好的pinboard HTML数组
     * @param unknown_type $aData数组
     * @param unknown_type 取消关注deleteType=2,其他传=1
     * @param unknown_type $uid
     * @param unknown_type 是否是我的最爱，最爱的话不用判断是否表过态
     * @param unknown_type $ifme是否需要显示关闭
     * @param unknown_type $feed评论
     *
     */
    public function __construct($feed=array(),$uid,$ifme=false,$is_share=true,$content=array()){
        $this->content = $content;
        $this->feed = $feed;
        
        $this->redis=new ml_model_rdsCount();

        $this->getUidRid($feed, $content);
        $this->uid=$uid;
        $this->ifme=$ifme;
        $this->is_share=$is_share;
        $this->get_nick();
        $this->get_cnt();
    
        $this->get_attitude();
        $this->get_comment();
        $this->get_ColCnt();
         
    
    }
    public function getUidRid($feed,&$content){
        if (empty($feed))
            return false;
        
        foreach ($feed as $value) {
            $this->aUid[]=$value['uid'];
            $this->aRid[]=$value['rid'];
            
            
            
        }
        
    
    
    }
    public function uniqueData($aData,&$comment){
        
    
    }
    public function output() {
        $oHash = new ml_model_rdsHash();
        
        foreach ($this->feed as $value) {
            $cnt = $this->content[$value['content_rid']];
            
            if($value['type'] == 9) {
                
                $value['is_quote'] = true;
                $value['col_id'] = $value['feed_info']['col_id'];
                $value['col_name'] = $value['feed_info']['col_name'];
                
            }
            if($this->uid == $cnt['uid']) { 
                $value['deleteType'] =  'deleteType=1';
            }else {
                $value['deleteType'] =  'deleteType=2';
            }
            // 转踩人的信息
            $value['quote_info']=array(
                    'uid'=>$value['uid'],
                    'content'=> $value['content'],
                    'nick'=> empty($this->aNicks[$cnt['uid']]) ? $oHash->getNickByUid($value['uid']) : $this->aNicks[$cnt['uid']]
            );
            
            $value['uid'] = $cnt['uid'];
            $value['content'] = $cnt['content'];
            $value['type_xrank'] = $cnt['type_xrank'];
            $value['comment'] = $value['content'];
            $value['gd_title'] = $cnt['gd_title'];
            $value['gd_price'] = $cnt['gd_price'];
            $value['like_cnt'] = intval($this->aLikeCnt[$cnt['rid']]);
            $value['cmt_cnt'] = intval($this->aCmtCnt[$cnt['rid']]);
            $value['quote_cnt'] = intval($this->aQuoteCnt[$cnt['rid']]);
            $value['nick'] = empty($this->aNicks[$cnt['uid']]) ?$oHash->getNickByUid($cnt['uid']) : $this->aNicks[$cnt['uid']];
            
            $value['canDel'] = true;
            
            $value['is_attitude'] = isset($this->aAttitude[$value['rid']]) ? true : false;
            $list[] = $value;
        }
        
        

        return ml_tool_pinOutput::parsePinboardTpl($list);
    
    }
    
    public function get_nick()
    {
        $this->aNicks = ml_tool_nick::uids2nicks($this->aUid);
    
        
    }
    public function get_cnt()
    {
        $rs = $this->redis->getAttitudeCount($this->aRid);
        /**
         * @todo
         */
        $this->aLikeCnt = $this->redis->get_data();
    
    }
    public function get_attitude()
    {
        if($this->uid)
        {
            $oIlike = new ml_model_dbILike();
            $rs = $oIlike->getListByUidRids($this->uid , $this->aRid);
            $this->aAttitude = Tool_array::format_2d_array($oIlike->get_data() , 'content_rid' , Tool_array::FORMAT_VALUE2VALUE2 ,'attitude');
        }
    }
    public function  get_comment(){
        $rs = $this->redis->getCommentCount($this->aRid);
        /**
         * @todo
         */
        $this->aCmtCnt = $this->redis->get_data();
    
    }
    public function  get_ColCnt(){
        $rs = $this->redis->getColCnt($this->aRid);
        /**
         * @todo
         */
        $this->aQuoteCnt = $this->redis->get_data();
    
    }
    
    
    
    
    
    
/* 
    private $uid;
    
    private $aRid = array();
    private $aUid = array();
    private $aNicks = array();
    private $aAttitude = array();
    private $aLikeCnt = array();
    private $aCmtCnt = array();
    private $aQuoteCnt = array();
    
    public function __construct($data,$uid)
    {
        $this->uid = $uid;
        
            
    
        foreach ($data as $row)
        {
            $this->aUid[] = $row['uid'];
            $this->aRid[] = $row['content_rid'];
        }
        
        
        
    }
    
    
    
    public function get_nick()
    {
        $oAccount = new ml_model_dbUserAccount();
        $rs = $oAccount->getNicksByUids($this->aUid);
        $this->aNicks = $oAccount->get_data();
    }
    public function get_cnt()
    {
        $oRedis = new ml_model_rdsCount();
        $rs = $oRedis->getAttitudeCount($this->aRid);
        $this->aLikeCnt = $oRedis->get_data();
        $re=$oRedis->getCommentCount($this->aRid);
        $this->aCmtCnt=$oRedis->get_data();
        
        
    }
    public function get_attitude()
    {
        if($this->uid)
        {
            $oIlike = new ml_model_dbILike();
            $rs = $oIlike->getListByUidRids($this->uid , $this->aRid);
            $this->aAttitude = Tool_array::format_2d_array($oIlike->get_data() , 'content_rid' , Tool_array::FORMAT_VALUE2VALUE2 ,'attitude');
        }
    }
    
    public function render_html_list()
    {
        if (empty($this->goods_data)) return ;
        
        
        $this->get_nick();
        $this->get_cnt();
        $this->get_attitude();
        
        foreach ($this->goods_data as $k => $row)
        {
            $this->goods_data[$k]['rid'] = $row['content_rid'];
            $this->goods_data[$k]['nick'] = $this->aNicks[$row['uid']];
            $this->goods_data[$k]['like_cnt'] = intval($this->aLikeCnt[$row['content_rid']]);
            $this->goods_data[$k]['cmt_cnt'] = intval($this->aCmtCnt[$row['content_rid']]);
            $this->goods_data[$k]['quote_cnt'] = intval($this->aQuoteCnt[$row['content_rid']]);
            $this->goods_data[$k]['is_attitude'] = isset($this->aAttitude[$row['content_rid']]) ? true : false;
            $this->goods_data[$k]['attitude_score'] = $this->aAttitude[$row['content_rid']];
            $this->goods_data[$k]['type_xrank'] = ML_CONTENT_XRANK_GOODS;
        }
        
        
        
        return ml_tool_pinOutput::parsePinboardTpl($this->goods_data , false);
    }
    
    
    public function indexPinBroad($feed,$uids,$current_uid) {
        
        $this->get_nick();
        $this->get_cnt();
        $this->get_attitude();
        
        var_dump($this->aNicks);
        var_dump($this->aLikeCnt);
        var_dump($this->aCmtCnt);
        var_dump($this->aAttitude);

        foreach($feed as $k => $content) {
    
            $content['nick']=$this->aNicks[$content['uid']];    //作者昵称
    
            $content['deleteType']=$content['uid']==$current_uid?"deleteType=1":"deleteType=2";
    
            $content['canDel'] = true;
    
            switch($content['type']) {
                case ML_FEED_TYPE_REPOST_COLLECTION:
                    $content['is_quote'] = true;
    
                    break;
                case ML_FEED_TYPE_ATTITUDE:
                    break;
            }
    
            $content['gd_price'] = $content['feed_info']['gd_price'];
            $content['gd_title'] = $content['feed_info']['gd_title'];
            $content['gd_url'] = $content['feed_info']['gd_url'];
            $content['gd_pic'] = $content['feed_info']['gd_pic'];
            $content['rid'] = $content['content_rid'];
            $content['nick'] = $this->aNicks[$content['uid']];
            
            $content['like_cnt'] = intval($this->aLikeCnt[$content['content_rid']]);
            $content['cmt_cnt'] = intval($this->aCmtCnt[$content['content_rid']]);
            
            $list[] = $content;
        }
    
        return ml_tool_pinOutput::parsePinboardTpl($list,false);
        
        
        foreach ($this->goods_data as $k => $row)
        {
            $this->goods_data[$k]['rid'] = $row['content_rid'];
            $this->goods_data[$k]['nick'] = $this->aNicks[$row['uid']];
            $this->goods_data[$k]['like_cnt'] = intval($this->aLikeCnt[$row['content_rid']]);
            $this->goods_data[$k]['cmt_cnt'] = intval($this->aCmtCnt[$row['content_rid']]);
            $this->goods_data[$k]['quote_cnt'] = intval($this->aQuoteCnt[$row['content_rid']]);
            $this->goods_data[$k]['is_attitude'] = isset($this->aAttitude[$row['content_rid']]) ? true : false;
            $this->goods_data[$k]['attitude_score'] = $this->aAttitude[$row['content_rid']];
            $this->goods_data[$k]['type_xrank'] = ML_CONTENT_XRANK_GOODS;
        }
        
        
        
        
        
    
    }
    
    
    
     */
}
